<template>
  <div class="BankCard">
    <div
      v-for="item in list"
      :key="item.id"
      class="cardBox"
    >
      <div class="card">
        <span
          class="leftIcon"
          @click="edit(item)"
        >
          <a-icon type="edit" />
        </span>
        <span class="content">{{ item.carBrand }}</span>
        <span
          class="righIcon"
          @click="delect(item)"
        >X</span>
      </div>
    </div>
    <div
      class="addCard"
      @click="addModal"
    >
      <span class="plusIcon">
        <a-icon type="plus" />
      </span>
    </div>
    <BankModal
      ref="bankModal"
      @ok="handleOk"
    />
  </div>
</template>
<script>
import BankModal from './bankModal.vue'
import { delSysDcarbrandClassifyConfig } from '@/api/system'
export default {
  name: 'BankCard',
  data () {
    return {
    }
  },
  props: {
    list: {
      type: Array,
      default: () => [
        { id: 1, carBrand: '奔驰' },
        { id: 2, carBrand: '宝马' },
        { id: 3, carBrand: '奥迪' },
        { id: 4, carBrand: '雷克萨斯' },
        { id: 5, carBrand: '凯迪拉克' },
        { id: 6, carBrand: '阿尔法罗密欧' },
        { id: 7, carBrand: '英菲迪亚' },
        { id: 8, carBrand: '沃尔沃' }
      ]
    },
    bankTitle: {
      type: String,
      default: ''
    }
  },
  inject: ['bankDataThis'],
  methods: {
    edit (item) {
      console.log('我点击了编辑')
      this.$refs.bankModal.edit({
        ...item
      }, this.bankTitle)
    },
    delect (record) {
      console.log('我点击了删除')
      delSysDcarbrandClassifyConfig({ ids: record.id }).then(res => {
        if (res.code === 0) {
          this.$message.success('删除成功')
          this.bankDataThis.getBankClass()
        } else {
          this.$message.error(res.meg || '删除失败')
        }
      })
    },
    addModal () {
      console.log('我点击了addmodal')
      this.$refs.bankModal.add(this.bankTitle)
    },
    handleOk () {
      console.log('点击了ok')
      this.bankDataThis.getBankClass()
    }
  },
  components: {
    BankModal
  }
}
</script>
<style  scoped>
.cardBox {
  display: inline-block;
  margin-bottom: 10px;
  margin-top: 10px;
  margin-right: 10px;
  height: 28px;
  line-height: 28px;
  background: #ffffff;
  border: 1px solid #d3d3d3;
  border-radius: 4px;
}
.card {
  width: 100%;
  height: 28px;
}
.content {
  padding: 0 20px;
}
.leftIcon {
  float: left;
  padding-left: 10px;
  color: #227fe6;
  cursor: pointer;
}
.righIcon {
  float: right;
  padding-right: 10px;
  color: #227fe6;
  cursor: pointer;
}
.addCard {
  display: inline-block;
  width: 100px;
  height: 28px;
  line-height: 28px;
  background: #ffffff;
  border: 1px solid #d3d3d3;
  border-radius: 4px;
  text-align: center;
  color: #227fe6;
  cursor: pointer;
}
</style>
